from tkinter import *
from lxg_tkinter import demos, Quitter


class Demo(Frame):
    def __init__(self, parent=None, **options):
        Frame.__init__(self, parent, **options)
        self.pack()
        Label(self, text='滑动条案例').pack()
        self.var = IntVar()
        # 创建滑动条
        Scale(self,
              label='选择一个数字',
              command=self.on_move,
              variable=self.var,
              from_=0,
              to=len(demos) - 1).pack()

        Scale(self,
              label='选择一个数字',
              command=self.on_move,
              variable=self.var,
              from_=0,
              to=len(demos) - 1,
              length=200,
              tickinterval=1,
              showvalue=YES,
              orient='horizontal').pack()
        # 按钮
        Quitter(self).pack(side=RIGHT)
        Button(self, text='运行案例', command=self.on_run).pack(side=LEFT)
        Button(self, text='状态', command=self.report).pack(side=RIGHT)

    def on_move(self, value):
        print('移动：', value)

    def on_run(self):
        pos = self.var.get()
        print("你的选择：", pos)
        demo = list(demos.values())[pos]  # 从位置映射值
        print(demo())

    def report(self):
        print(self.var.get())


if __name__ == '__main__':
    Demo().mainloop()